/*
 * @Author: RYPY
 * @Date: 2021-02-20 17:48:22
 * @LastEditors: RYPY
 * @LastEditTime: 2021-03-17 00:22:37
 */
var express = require('express');
const {serverPath,Msg}=require("../until/config");
const DB=require("../until/DB");
var router = express.Router();

//首页精品课程/同步课程的数据接口
router.get("/courseinfo",async (req,res,next)=>{
  //type的取值同步课程是1，精品课程是2
  let {type=1}=req.body;
  let sql =`select c.id,c.cid,title,price,concat('${serverPath}/course_img/',image_src) image_src,type,type_name,area_name,grade_name,subject_name,category_name,tid,c.status,COUNT(o.cid) num from e_course c LEFT JOIN e_order o ON c.cid=o.cid WHERE type=${type} GROUP BY c.cid ORDER BY num DESC LIMIT 8`;
  let [err,result]=await DB.query(sql);
  if(!err){
    res.send(Msg(200,'ok',result));
  }else{
    next("稍后再试！");
  }
});

module.exports = router;
